home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / faq / comp / macintos / programm < prev    next >
Text File  |  1994-04-11  |  64KB  |  1,639 lines

  1. Path: bloom-beacon.mit.edu!hookup!news.moneng.mei.com!howland.reston.ans.net!EU.net!sunic!trane.uninett.no!nac.no!news.kth.se!hemul.nada.kth.se!d88-jwa
  2. From: d88-jwa@hemul.nada.kth.se (Jon WΣtte)
  3. Newsgroups: comp.sys.mac.programmer,comp.answers,news.answers
  4. Subject: The Mac Programming Public Domain FAQ Answer sheet.
  5. Followup-To: comp.sys.mac.programmer
  6. Date: 11 Apr 1994 09:13:50 GMT
  7. Organization: The Royal Institute of Technology
  8. Lines: 1621
  9. Approved: news-answers-request@MIT.Edu
  10. Expires: 1 May 94 00:00:00 GMT
  11. Message-ID: <2ob4ce$8l0@news.kth.se>
  12. NNTP-Posting-Host: hemul.nada.kth.se
  13. Mime-Version: 1.0
  14. Content-Type: text/plain; charset=iso-8859-1
  15. Content-Transfer-Encoding: 8bit
  16. Xref: bloom-beacon.mit.edu comp.sys.mac.programmer:44946 comp.answers:4851 news.answers:17895
  17.  
  18. Archive-name: macintosh/programming-faq 
  19.  
  20. The Public Domain Mac Programming FAQ Answer sheet.
  21. Last update: 931023
  22.  
  23. This sheet was started by and is presently maintained by Jon 
  24. W{tte, whom you may reach as h+@nada.kth.se. If there is 
  25. anything you find errant, missing or in need of an update, 
  26. please send me your submission and I will include it (I can't 
  27. promise correct attributions, but I will try) All FAQ Answer 
  28. submissions sent to me will be considered to be in the public 
  29. domain unless stated otherwise (in which case they will not be 
  30. included in this FAQ sheet) 
  31.  
  32. This sheet is currently archived on nada.kth.se where you can 
  33. reach it using afs as /afs/nada.kth.se/public/ftp/pub/hacks/mac-f
  34. aq/CSMP_PD_FAQ or using anonymous FTP (GIVE YOUR E-MAIL ADDRESS 
  35. AS PASSWORD!) as pub/hacks/mac-faq/CSMP_PD_FAQ 
  36.  
  37. I will try to update this sheet every three weeks or so.
  38.  
  39. This sheet is divided into several parts; each of which covers a 
  40. general area which often gets asked about in the Internet 
  41. newsgroup comp.sys.mac.programmer. Please download a copy of 
  42. this answer sheet and search it before you post to the 'net, to 
  43. help reduce bandwidth. 
  44.  
  45. There is NO or VERY LIMITED error checking in these code 
  46. examples, FOR BREVITY ONLY. You should make sure you ALWAYS 
  47. check ALL return codes, and handle any that you are not prepared 
  48. to deal with appropriately. 
  49.  
  50. The coding style used in the example C code is my own, and 
  51. you'll have to live with it.
  52.  
  53. The groups are (you may search for *<number>* to jump directly 
  54. to a group with its questions and answers) 
  55.  
  56. 0) Development and debugging tools and documentation for the Mac 
  57. 1) Files and the File Manager 
  58. 2) Serial ports 
  59. 3) TCP/IP and sockets 
  60. 4) AppleEvents and the Apple Object Model 
  61. 5) AppleScript
  62. 6) Drawing using QuickDraw 
  63. 7) Drawing NOT using QuickDraw (aka directly to screen) 
  64. 8) Cache issues and other processor differences 
  65. 9) What about pre-emptive multitasking? 
  66. 10) Handles; they are driving me crazy; Memory issues 
  67. 11) _Gestalt and compatibility 
  68. 12) Standalone code and dynamic linking 
  69. 13) Keyboard & Mouse for Games and Screen Savers 
  70. 14) QuickTime 
  71. 15) Windows, Menus, Dialogs
  72. 16) Ice Cream and Frozen Yoghurt 
  73.  
  74. *0* Development and debugging tools for the Macintosh 
  75.  
  76. 0.1) Q: What do I need to start writing Macintosh software? 
  77.  
  78. A: A Mac, a lot of time, and a few hundred $. Although you can 
  79. develop software on a Classic-type machine, it is not to be 
  80. attempted by the weak of heart or stressed of time. If you're 
  81. doing paid work and/or work for a company, a Quadra-class 
  82. machine or Centris 650 or better is almost a must; remember that 
  83. your time costs your employer much more than just your salary. 8 
  84. MB is a minimum to run at all comfortably, and Virtual Memory is 
  85. not suited for development work. Similarly; if you don't have at 
  86. least 20 MB free on your hard disk (40 MB for MPW) you need to 
  87. buy more space. 
  88.  
  89. You need a development system such as Think C, CodeWarrior C++, 
  90. MPW C or Prograph, you need at least some of the New Inside Mac 
  91. books (Toolbox Essentials, Files, Memory come to mind) and a 
  92. good entry-level third-party book may help. 
  93.  
  94. Once you are up to speed on the general layout of the Mac and 
  95. its toolboxes, you should call APDA and order the monthly 
  96. developer mailing, which will give you a CD chock full of 
  97. documentation, utilities and system software once a month. You 
  98. will also, obviously, need a CD player; one of which Apple's own 
  99. CD300 is a very good buy at the time of writing this. If you 
  100. don't have the dough for the monthly mailing ($250/year) you can 
  101. order a _develop_ subscription; this quarterly magazine 
  102. ($30-$50/year) comes with a CD containing all Inside Mac 
  103. documentation.
  104.  
  105. Another tool which many find a must-have is the Think Reference 
  106. version 2.0.1, containing reference material on the most used 
  107. parts of the Mac toolbox with lightning-fast look-up and mostly 
  108. correct usage hints and code snippets. 
  109.  
  110. 0.2) Q: What is the most used Macintosh development language? 
  111.  
  112. A: Out of products on the market, I have no idea; both MPW and 
  113. Think products appear to be used. Lately, CodeWarrior has come 
  114. out of nowhere and grabbed a large share of the market 
  115. visibility because they have the fastest compiler and they 
  116. generate PowerPC code as well as 68K code. Among hobbyists, the 
  117. Think products from Symantec are most popular because of the low 
  118. price, and steep educational discounts, and, of course, the 
  119. easily approachable interface! 
  120.  
  121. The Think C linker only strips dead code on a FILE level basis 
  122. (and this is when you turn on "Smart Linking") The MPW linker 
  123. (of no specified IQ, as someone so eloquently put it :-) strips 
  124. dead code by the function, as does CodeWarrior. That may be part 
  125. of the reason the Think C linker is ten times faster than the 
  126. MPW linker. 
  127.  
  128. In the beginning, the Mac was programmed using Mc68000 assembly 
  129. or Pascal; this was reflected in the Old Inside Mac volumes 
  130. which only gave Pascal-style and assembly-style interfaces to 
  131. the Mac toolbox. These days, Apple tells us to use C or even 
  132. better C++ for developing new applications, as that will speed 
  133. up the transition to PowerPC and also coming cross-platform 
  134. efforts. (Language Systems have a Pascal for PowerPC product 
  135. now, but I don't know about pricing or quality)
  136.  
  137. There are also at least two Fortran compilers, at least three 
  138. SmallTalk implementations (ObjectWorks, SmallTalk/V and 
  139. SmallTalkAgents), a world-class LISP/CLOS implementation 
  140. (Macintosh Common Lisp 2.0) and a Modula/2 implementation. 
  141. Apparently, using Envy/packager, you can strip out unused code 
  142. pretty effectively from Digitalk and PP apps, which are then 
  143. smaller (and of course more memory efficient) than C++ apps. 
  144.  
  145. Metrowerks have a Pascal and a Modula II compiler. They're
  146. building C and C++ for both 68k and coming PPC Macs, and
  147. will also have a PowerPC Pascal.
  148.  
  149. CSI has MacForth, of which I only know the name and someone who 
  150. says it's pretty good.
  151.  
  152. There is another good Common Lisp implementation: Procyon Common 
  153. Lisp. I don't know if it is actively supported, but Procyon CL 
  154. is also available for DOS, OS/2 and Windows (as Allegro CL/PC) 
  155. and actively developed. 
  156.  
  157. 0.3) Q: Where do I find a public domain C compiler for the Mac. 
  158. Is there a GCC for the mac? What about the FSF boycott of Apple 
  159. products? 
  160.  
  161. A: There is no really good solution for a "for-free" C 
  162. development system for the Mac. GCC has been ported, but 
  163. requires the MPW shell and MPW assembler to run; these have to 
  164. be bought from APDA. There is a standalone port of GCC 1.37 on 
  165. nic.switch.ch:software/mac/src/think_c. There was a freely 
  166. available C compiler called Harvest C, which was somewhat 
  167. unstable but usable for smaller programs; it was abandoned by 
  168. the original author Eric W Sink because of a lack of time and 
  169. later taken up by the TopSoft project.
  170.  
  171. The FSF boycott of Apple products means they will not talk to 
  172. you if you ask them for help in doing a Mac port, and they will 
  173. not incorporate your changes into their main code base. However, 
  174. they still allow others to port GNU stuff to the Mac, and it has 
  175. been done with most of the application-like GNU programs (bison, 
  176. flex, perl (not really part of GNU), ...) 
  177.  
  178. gcc-1.37r14 V1.1 standalone is available for ftp at the address below.
  179.  
  180. (A) nic.switch.ch:software/mac/src/think_c/GCC_1.37.1r14.sit.bin
  181. (B) nic.switch.ch:software/mac/src/think_c/GCC_1.37.1r14_src.sit.bin
  182. (C) nic.switch.ch:software/mac/src/think_c/GCC_1.37.1r14_libsrc.sit.bin
  183. (D) nic.switch.ch:software/mac/src/think_c/GCC_1.37.1r14_includes.sit.bin
  184.  
  185. Exhibit (A) will be of interest to users who wish to play with an actual
  186. application. This can not be described as finished, but it is at least
  187. functional. Comments and feedback by e-mail to jrrk@camcon.co.uk are
  188. invited. Exhibit (B) will be of interest to those who like to tinker with
  189. source code and crib ideas for their own programs.
  190. Exhibit (C) will be useful to those who need a library to simplify porting
  191. of code from UNIX or who are otherwise fed up with the incompatabilities of
  192. the standard C library provided with THINK C. It is also needed to build
  193. (B) into a complete application, and also provides the basis of the object
  194. libraries supplied with (A).
  195. Exhibit (D) are the conventional (i.e. non mac toolbox) headers that are
  196. needed to compile the source code and for anyone who would like to write
  197. ANSI-C programs. However the number of hacks needed to gcc to make it
  198. support mac native toolbox applications is likely to make it unreliable as
  199. an ANSI compiler. For this purpose, I have found MacMiNT to be a better
  200. alternative.
  201.  
  202. Highly recommended is to get the toolbox includes for MPW 3.2 and the
  203. 'spinside macintosh' hypercard stack from ftp.apple.com These will give
  204. users an idea of how to go about programming stand-alone Mac applications.
  205.  
  206. 0.4) Q: Are there any other free Mac development platforms? 
  207.  
  208. A: Yerk and Mops. These are object oriented languages based on 
  209. the old product Neon which itself was based on Forth. They are 
  210. available with Manuals at oddjob.uchicago.edu (anonymous FTP). 
  211.  
  212. Plus, there's MacGambit, MacScheme, xlisp, and MacMETH which is 
  213. the actual ETH (read: Nick Wirth's group) Modula 2, all for free 
  214. via FTP.
  215.  
  216. And OpenProlog. And SIOD (Scheme in One Defun) And [mail in more 
  217. if you dare]
  218.  
  219. 0.5) Q: What's the difference between the MPW and Think 
  220. environments? 
  221.  
  222. A: The main difference is that Think is an integrated 
  223. environment, while MPW provides you with a command-line shell 
  224. for your Mac and tools to use in it. MPW also has a slightly 
  225. higher systems demand and a much slower linker. 
  226.  
  227. The good thing about MPW is that you can write scripts and make 
  228. files to do anything you want in the way you want it. Think 
  229. still doesn't have a viable solution to do a build that requires 
  230. more than one link operation, or has more than one destination 
  231. file. 
  232.  
  233. For the MPW environment, there are three source level debuggers; 
  234. SADE, SourceBug and Voodoo Monkey. The latter is an experimental 
  235. debugger with support for threads debugging; the middle is 
  236. bundled with MPW while SADE has to be bought separately (but is 
  237. fully scriptable in its own scripting language) 
  238.  
  239. The Think environments have their own integrated debuggers; the 
  240. Think Pascal one has a lot of useful features while the Think 
  241. C/C++ one is a little more basic (but is gaining in 
  242. functionality with each release) Stepping through source code 
  243. and looking at variables is generally faster and easier in Think 
  244. than the MPW debuggers. 
  245.  
  246. Any commercial Mac developer should have both Think and MPW of 
  247. whatever language they prefer (Pascal, C or C++) 
  248.  
  249. 0.6) Q: What is a good low-level debugger for the Mac? 
  250.  
  251. A: MacsBug is freely available for ftp from ftp.apple.com; log 
  252. in as user anonymous and give your FULL e-mail address as 
  253. password. MacsBug is your basic monitor-type debugger that takes 
  254. a few hundred Ks of memory, and lets you break, step, 
  255. disassemble, look at the stack etc of most anything running on 
  256. your Mac. Since it's free (it's also on the developer CDs) and 
  257. provides most of the functionality you need, this is a popular 
  258. choice. 
  259.  
  260. TMON is another debugger which sports a more mac-like interface; 
  261. it provides windows and uses the mouse. It can take as little or 
  262. much memory as you want by excluding or including certain areas 
  263. of functionality. A nice touch is the 6502 disassembler that you 
  264. can use to de-bug the code the IOP processors run on the Mac 
  265. IIfx and Quadra 900/950. 
  266.  
  267. Jasik Designs have a debugger called The Debugger which can do 
  268. both low- and high-level debugging, with or without source and 
  269. for all types of code, application, code resources, everything. 
  270. This is the debugger of choice for many large developers because 
  271. of its high power and many features not found anywhere else. 
  272. However; newcomers beware! This is the Lamborghini of debuggers; 
  273. if you know how to drive it, it is the fastest way from A to B; 
  274. if you don't, you'll just end up in the ditch. As a lady put it:
  275. "The man wouldn't know a user interface if it bit him in the
  276. rear."
  277.  
  278. 0.7) Q: Are there any visual developments environments for the 
  279. Mac (comparable to Visual C++)?
  280.  
  281. A: There is no Visual C++ as such. However, there is a C++ 
  282. parser/editor called ObjectMaster which provides good browsing 
  283. and editing capabilities if you already have a C++ compiler. 
  284. Think C++ also comes with a browser built-in, and you can draw 
  285. dialogs/windows using plain old ResEdit, even for your custom 
  286. view types. 
  287.  
  288. AppMaker is a GUI builder/code generator.  Granted, it's not as 
  289. nice as VC++, but it's quite a product in any case.
  290.  
  291. Also, Neuron Data has their UI tool called Open Interface, which 
  292. is better than VC++ and creates code portable across 35 
  293. platforms. Unfortunately it's $2500 per developer per platform. 
  294. (There's also two other cross-platform products called XVT and 
  295. Galaxy, the former has gotten flak on UseNet while the latter 
  296. reportedly has decent networking support)
  297.  
  298. There is a fully visual, dynamic, object oriented data-flow-drive
  299.   n programming language for the Mac called Prograph Corporate 
  300. Programming Something-or-other (CPX). It is expensive ($1500) 
  301. but offers a built-in database, easy interfaces to existing data 
  302. bases, very high productivity in implement-test-debug cycling 
  303. and also offers cross-platform capabilities (it comes with a 
  304. class library which, when your code is written using it, works 
  305. under Windows after re-compilation) 
  306.  
  307. There is a crossing between SmallTalk and C++ that is called 
  308. Component Workshop; although it seems large and slowly evolving, 
  309. it does offer some promising features not found in C++ itself. 
  310.  
  311. There is also something called SmallTalkAgents that makes it 
  312. easy to create Mac applications using SmallTalk. If you'd rather 
  313. do Common Lisp, Macintosh Common Lisp offers a Common Lisp 
  314. Object System with support for most Mac interface items; you can 
  315. edit code while it is running and build stand-alone 
  316. applications. 
  317.  
  318. However, all of these tools generate rather larger binaries with 
  319. larger system demands than a program written in C. On the other 
  320. hand; C++ programs require more memory and disk space than 
  321. programs written in assembly. It's a trade-off, and I believe 
  322. this type of tools is the wave of the near future. 
  323.  
  324. 0.8) Q: What class libraries are there for the Mac? 
  325.  
  326. A: Apart from the libraries mentioned above, there are three 
  327. contenders: MacApp, TCL, and OOPC. On the horizon may be 
  328. Bedrock. 
  329.  
  330. MacApp is a heavy-duty class library that has tons of features 
  331. and a steep learning curve; it runs under MPW with Pascal or 
  332. C++, and also under Think Pascal 4.0 A major application written 
  333. in MacApp is PhotoShop. 
  334.  
  335. TCL stands for Think Class Library and comes with Think Pascal, 
  336. C or C++. It is a smaller library that still fills most peoples 
  337. needs; since Think C implements a subset of C++ (the most 
  338. important OO concepts such as virtual functions and inheritance) 
  339. and the TCL is carefully written not to take advantage of any 
  340. C++ features not in Think C, you can use it with Think C. A 
  341. major application written in TCL is Lotus 1-2-3. 
  342.  
  343. OOPC is a newcomer in the field, and uses plain ANSI C. However, 
  344. it mangles the pre-processor to provide you with a system with 
  345. full inheritance, virtual functions, and dynamic re-binding of 
  346. functions for classes or individual objects. Start-up is slow, 
  347. since all "linking" of virtual functions and classes is made at 
  348. run-time, but performance otherwise is good. A Windows version 
  349. is promised for later this year. 
  350.  
  351. 0.9) Q: How should I debug and test my software? 
  352.  
  353. A: Get ahold of, and install, the extensions DoubleTrouble, 
  354. DisposeResource and EvenBetterBusError. They will catch 80% of 
  355. any memory related bugs you may have, including many bugs that 
  356. follow NULL handles or pointers. 
  357.  
  358. A low-level debugger is required, and while you install it, 
  359. install the "leaks" dcmd which will help you catch memory leaks 
  360. in your application. All of these tools are available from 
  361. ftp.apple.com. 
  362.  
  363. *1* Files and the File Manager 
  364.  
  365. 1.1) Q: How do I tell fopen() to open a file the user has 
  366. selected using StandardGetFile? 
  367.  
  368. A: The "standard" ANSI C file functions are less than well 
  369. suited for the Macintosh way of doing things. However, if you 
  370. are doing a port for your own enjoyment and benefit (or maybe 
  371. for in-house work) you can use the following function: (see 
  372. below about converting a wdRefNum into a vRefNum/parID pair) 
  373.  
  374. *code*
  375. FILE *
  376. fopen_mac ( short vRefNum , long parID , char * fileName , char * mode ) {
  377.  
  378. short oldVol ;
  379. short aVol ;
  380. long aDir , aProc ;
  381. FILE * ret = NULL ;
  382.  
  383.     if ( GetVol ( NULL , & oldVol ) ) {
  384.         return NULL ;
  385.     }
  386.     if ( GetWDInfo ( oldVol , & aVol , & aDir , & aProc ) ) {
  387.         return NULL  ;
  388.     }
  389.     if ( HSetVol ( NULL , vRefNum , parID ) ) {
  390.         return NULL ;
  391.     }
  392.     ret = fopen ( fileName , mode ) ;
  393.     if ( HSetVol ( aVol , aDir ) ) {
  394.         /* an error we can't currently handle */
  395.     }
  396.     if ( SetVol ( oldVol ) ) {
  397.         /* an error we can't currently handle */
  398.     }
  399.     return ret ;
  400. }
  401. *end*
  402.  
  403. All of the above is necessary for one reason or another - if you 
  404. are interested, by all means look HSetVol up in Think Reference 
  405. 2.0 or New Inside Mac: Files. 
  406.  
  407. In older versions of MPW; this wouldn't work since the MPW 
  408. libraries used to do a GetVol and explicitly use that value by 
  409. itself. 
  410.  
  411. 1.2) Q: When can I use the HOpen, HCreate etc file calls? Are 
  412. they only System 7 calls? 
  413.  
  414. A: All the HXxx calls that take a vRefNum and parID as well as 
  415. the file name are implemented in glue that works on any system 
  416. that has HFS (meaning 3.2 and up with the HD20 INIT, and all 
  417. systems from System 6 and up) 
  418.  
  419. The glue is available in MPW 3.2 and up, and Think C 5.0 and up. 
  420. This goes for all HXxx calls except HOpenDF; therefore, if you 
  421. are interested in System 6 compatibility, use HOpen instead and 
  422. make sure you don't allow file names beginning with a period. 
  423.  
  424. 1.3) Q: Why do you say wdRefNum sometimes and vRefNum sometimes? 
  425. Why do you say parID sometimes and dirID sometimes? 
  426.  
  427. A: When the Mac first made an appearance in 1984, it identified 
  428. files by using a vRefNum (volume reference number meaning a 
  429. floppy disk or later hard disk) and a name. Once HFS saw the 
  430. light of day, folders within folders became a reality, and you 
  431. needed a dirID as well to point out what folder you really meant 
  432. on the volume. However, older programs that wasn't being 
  433. rewritten still knew nothing about directory IDs, so Apple had 
  434. SFGetFile make up "fake" vRefNums that didn't just specify a 
  435.  
  436. volume, but also a parent folder. These are called wdRefNums 
  437. (for working directory) and were a necessary evil invented in 
  438. 1985. You should not create (or, indeed, use) wdRefNums 
  439. yourself. 
  440.  
  441. There is a system-wide table that maps wdRefNums onto 
  442. vRefNum/parID pairs. There is a limit to the size of this table. 
  443. A dirID and a parID is almost the same thing; you say "parID" 
  444. when you mean the folder something is in, while you say a 
  445. "dirID" when you mean the folder itself. If you for instance 
  446. have a folder called "Foo" with a folder called "Bar" in it, the 
  447. parID for "Bar" would be the dirID for "Foo." 
  448.  
  449. 1.4) Q: How do I convert a wdRefNum as returned by SFGetFile 
  450. into a vRefNum/parID pair to use with the HXxx calls. 
  451.  
  452. A: Use GetWDInfo, which is declared as: 
  453.  
  454. Pascal OSErr GetWDInfo ( short wdRefNum , short * vRefNum , long 
  455. * parID , OSType * procID ) ; 
  456.  
  457. The procID parameter must be non-NULL and point to an OSType 
  458. variable, but the value of that variable can and should be 
  459. ignored. 
  460.  
  461. It is recommended that, as soon as you get your hands on a 
  462. wdRefNum, for instance from SFGetFile, you directly convert it 
  463. into a vRefNum/parID pair and always use the latter to reference 
  464. the folder. 
  465.  
  466. 1.5) Q: How do I select a folder using SFGetFile? 
  467.  
  468. A: This requires a custom dialog with a filter proc. It is too 
  469. complicated to show here, but not totally impossible to 
  470. comprehend. There is sample code on ftp.apple.com, in the 
  471. directory dts/snippets, on how to do this. 
  472.  
  473. 1.6) Q: How do I get the full path of a file referenced by a 
  474. vRefNum, parID and name? 
  475.  
  476. A: You don't. 
  477.  
  478. OK, I cheated you. There is exactly ONE valid reason to get the 
  479. full path of a file (or folder, for that matter) and that is to 
  480. display its location to the user in, say, a settings dialog. To 
  481. actually save the location of the file you should do this: 
  482. (assuming the file is in an FSSpec called theFile - you can use 
  483. FSSpecs in your program even if you don't run under System 7; 
  484. just make your own MyFSMakeFSSpec that fills in the FSSpec 
  485. manually if it's not implemented) 
  486.  
  487. *code*
  488. if ( ! aliasManagerAvailable ) { /* System 6 ? */
  489.     GetVolumeName ( theFile -> vRefNum , vName ) ;
  490.     GetVolumeModDate ( vRefNum , & date ) ;
  491.     Save ( vName , date , parID , fileName ) ;
  492. } else {
  493.     NewAlias ( NULL , theFile , & theAlias ) ;
  494.     Save ( theAlias ) ;
  495.     DisposeHandle ( ( Handle ) theAlias ) ;
  496. }
  497. *end*
  498.  
  499. If you are really concerned about these issues (of course you 
  500. are!) you should save BOTH of these methods when available, and 
  501. load back whatever is there that you can handle; since users may 
  502. be using your application in a mixed System 6/System 7 
  503. environment. 
  504.  
  505. To get back to the file is left as an exercise for the reader. 
  506.  
  507. To open a file using fopen() or the Pascal equivalent, see above 
  508. about using and not using HSetVol. 
  509.  
  510. 1.7) Q: What about actually getting the full path for a file? I 
  511. promise I will only use it to show the location of a file to the 
  512. user! 
  513.  
  514. A: Enter PBGetCatInfo, the Vegimatic of the Mac file system. Any 
  515. Mac hacker of knowledge has taken this system call to his heart. 
  516. What you do is this: 
  517.  
  518. *code*
  519. OSErr
  520. GetFolderParent ( FSSpec * fss , FSSpec * parent ) {
  521.  
  522. CInfoPBRec rec ;
  523. short err ;
  524.  
  525.     * parent = * fss ;
  526.     rec . hFileInfo    . ioNamePtr = parent -> name ;
  527.     rec . hFileInfo    . ioVRefNum = parent -> vRefNum ;
  528.     rec . hFileInfo    . ioDirID = parent -> parID ;
  529.     if ( parent -> name [ 0 ] ) {
  530.         rec . hFileInfo . ioFDirIndex = 0 ;
  531.     } else {
  532.         rec . hFileInfo . ioFDirIndex = -1 ;
  533.     }
  534.     rec . hFileInfo    . ioFVersNum = 0 ;
  535.     err = PBGetCatInfoSync ( & rec ) ;
  536.     if ( ! ( rec . hFileInfo . ioFlAttrib & 0x10 ) ) { /* Not a folder */
  537.         if ( ! err ) {
  538.             err = dirNFErr ;
  539.         }
  540.     } else {
  541.         parent -> parID = rec . dirInfo . ioDrParID ;
  542.         parent -> name [ 0 ] = 0 ;
  543.     }
  544.     return err ;
  545. }
  546.  
  547.  
  548. OSErr
  549. GetFullPathHandle ( FSSpec * fss , Handle * h ) {
  550.  
  551. Handle  tempH = NULL ;
  552. short err ;
  553. FSSpec fs = * fss ;
  554.  
  555.     while ( fs . parID > 1 ) {
  556.         tempH = NULL ;
  557.         PtrToHand ( & fs . name [ 1 ] , & tempH , fs . name [ 0 ] ) ;
  558.         PtrAndHand ( ( void * ) ":" , tempH , 1 ) ;
  559.         HandAndHand ( * h , tempH ) ;
  560.         SetHandleSize ( * h , 0L ) ;
  561.         HandAndHand ( tempH , * h ) ;
  562.         DisposeHandle ( tempH ) ;
  563.         tempH = NULL ; 
  564.         GetFolderParent ( & fs , & sSpec ) ;
  565.         fs = sSpec ;
  566.     }
  567.     GetVolName ( fs    . vRefNum , fs . name ) ;
  568.     PtrToHand ( & fs . name [ 1 ] , & tempH , fs . name [ 0 ] ) ;
  569.     PtrAndHand ( ( void * ) ":" , tempH , 1 ) ;
  570.     HandAndHand ( * h , tempH ) ;
  571.     SetHandleSize ( * h , 0L ) ;
  572.     HandAndHand ( tempH , * h ) ;
  573.     DisposeHandle ( tempH ) ;
  574.     tempH = NULL ;
  575.     if ( ! IsFolder ( fss ) ) {
  576.     SetHandleSize ( * h , GetHandleSize ( * h ) - 1 ) ; // Remove colon }
  577.     return 0 ;
  578. }
  579. *end*
  580.  
  581. 1.8) Q: So how do I get the names of the files in a directory? 
  582.  
  583. A: You use PBGetCatInfo again, but this time you set ioFDirIndex 
  584. to 1 or more (you need to know the dirID and vRefNum of the 
  585.  
  586. folder you're interested in) You then call PBGetCatInfoSync for 
  587. values of ioFDirIndex from 1 and up, until you get an fnfErr. 
  588. Any other err means you are not allowed to get info about THAT 
  589. item, but you may be for the next. Then collect the names in the 
  590. string you made ioNamePtr point to as you go along. Note that 
  591. you need to fill in the ioDirID field for each iteration through 
  592. the loop, and preferrably clear the ioFVersNum as well. 
  593.  
  594. Note that the contents of a directory may very well change while 
  595. you are iterating over it; this is most likely on a file server 
  596. that more than one user uses, or under System 7 where you run 
  597. Personal File Share. 
  598.  
  599. 1.9) Q: How do I find the name of a folder for which I only know 
  600. the dirID and vRefNum? 
  601.  
  602. A: You call (surprise!) PBGetCatInfo! Make ioNamePtr point to an 
  603. empty string (but NOT NULL) of length 63 (like, an Str63) and 
  604. ioFDirIndex negative (-1 is a given winner) - this makes 
  605. PBGetCatInfo return information about the vRefNum/dirID folder 
  606. instead of the file/folder specified by vRefNum, parID and name. 
  607.  
  608. 1.10) Q: How do I make the Finder see a new file that I created? 
  609. Or if I changed the type of it; how do I display a new icon for 
  610. it? 
  611.  
  612. A: You call (surprise!) PBGetCatInfo followed by PBSetCatInfo 
  613. for the FOLDER the file is in. Inbetween, you should set 
  614. ioDrMdDat to the current date&time. Code: 
  615.  
  616. *code*
  617. OSErr
  618. TouchFolder ( short vRefNum , long parID ) {
  619.  
  620. CInfoPBRec rec ;
  621. Str63 name ;
  622. short err ;
  623.  
  624.     rec . hFileInfo . ioNamePtr = name ;
  625.     name [ 0 ] = 0 ;
  626.     rec . hFileInfo . ioVRefNum = vRefNum ;
  627.     rec . hFileInfo . ioDirID = parID ;
  628.     rec . hFileInfo . ioFDirIndex = -1 ;
  629.     rec . hFileInfo . ioFVersNum = 0 ;
  630.     err = PBGetCatInfoSync ( & rec ) ;
  631.     if ( err ) {
  632.         return err ;
  633.     }
  634.     GetDateTime ( & rec . dirInfo . ioDrMdDat ) ;
  635.     rec . hFileInfo . ioVRefNum = vRefNum ;
  636.     rec . hFileInfo . ioDirID = parID ;
  637.     rec . hFileInfo . ioFDirIndex = -1 ;
  638.     rec . hFileInfo . ioFVersNum = 0 ;
  639.     rec . hFileInfo . ioNamePtr [ 0 ] = 0 ;
  640.     err = PBSetCatInfoSync ( & rec ) ;
  641.     return err ;
  642. }
  643. *end*
  644.  
  645. 1.11) Q: Aren't we done with PBGetCatInfo soon? 
  646.  
  647. A: Well, it turns out that you can also find out whether an 
  648. FSSpec is a file or a folder by calling PBGetCatInfo and check 
  649. bit 4 (0x10) of ioFlAttr to see whether it is a folder. You may 
  650. prefer to call ResolveAliasFile for this instead. 
  651.  
  652. You can also check the script of the file's title using 
  653. PBGetCatInfo and check the ioFlFndrXInfo field if you want to 
  654. work with other script systems than the Roman system. 
  655.  
  656. Another common use is to find out how many items are in a 
  657. folder; the modification date of something or the correct 
  658. capitalization of its name (since the Mac file system is case 
  659. independent BUT preserves the case the user uses) 
  660.  
  661. 1.12) Q: How do I set what folder should initially be shown in 
  662. the SFGetFile boxes? 
  663.  
  664. A: You stuff the dirID you want to show into the lo-mem global 
  665. CurDirStore, and the NEGATIVE of the vRefNum you want into the 
  666. lo-mem global SFSaveDisk. 
  667.  
  668. If you are using CustomGetFile and return sfSelectionChanged 
  669. from an "init" message handler, you must remember to clear the 
  670. script code, else the selection will not change. 
  671.  
  672. 1.13) Q: How do I find the folder my application started from? 
  673. How do I find the application file that's running?
  674.  
  675. A: Under System 7, you call GetCurrentProcess, followed by 
  676. GetProcessInformation with a pointer to an existing FSSpec in 
  677. the parameter block. This will give you your file, and, by using 
  678. the vRefNum and parID, the folder the application is in.
  679.  
  680. Beware from writing to your applications resource or data forks; 
  681. the former breaks on CDs/write protected floppies/file 
  682. servers/virus checkers, the latter fails on PowerPC as well as 
  683. in the above cases.
  684.  
  685. *2* Serial ports 
  686.  
  687. 2.1) Q: How do I get at the serial ports? 
  688.  
  689. A: You call OpenDriver for the names "\p.AOut" and "\p.AIn" to 
  690. get at the modem port, and "\p.BOut" and "\p.BIn" for the 
  691. printer port. The function RAMSDOpen was designed for the 
  692. original Mac with 128 kB of memory and 64 kB of ROM, and has 
  693. been extinct for several years. 
  694.  
  695. However, many users use their serial ports for MIDI, LocalTalk, 
  696. graphic tablets, or what have you and have installed an 
  697. additional serial port card to get more ports. What you SHOULD 
  698. do as a good application is to use the Comms Toolbox Resource 
  699. Manager to search for serial resources; this requires that the 
  700. Comms Toolbox is present (true on earlier System 6 with an INIT, 
  701. on later System 6 and System 7 always, as well as on A/UX) and 
  702. that you have initialized the comms resource manager. The exact 
  703. code follows (adapted from Inside Mac Comms Toolbox): 
  704.  
  705. *code*
  706. #include <CommsResources.h>
  707. OSErr
  708. FindPorts ( Handle * portOutNames , Handle * portInNames , Handle * names , Handle * iconHandles ) {
  709.  
  710. OSErr ret = noErr ;
  711. short old = 0 ;
  712. CRMRec theCRMRec , * found ;
  713. CRMSerialRecord * serial ;
  714.  
  715.     * portOutNames = NewHandle ( 0L ) ;
  716.     * portInNames = NewHandle ( 0L ) ;
  717.     * names = NewHandle ( 0L ) ;
  718.     * iconHandles = NewHandle ( 0L ) ;
  719.     while ( ! ret ) {
  720.         theCRMRec . crmDeviceType = crmSerialDevice ;
  721.         theCRMRec . crmDeviceID = old ;
  722.         found = ( CRMRec * ) CRMSearch ( ( QElementPtr ) & theCRMRec ) ;
  723.         if ( found ) {
  724.             serial = ( CRMSerialRecord * ) found -> crmAttributes ;
  725.             old = found -> crmDeviceID ;
  726.             PtrAndHand ( & serial -> outputDriverName , * portOutNames ,
  727.                 sizeof ( serial -> outputDriverName ) ) ;
  728.             PtrAndHand ( & serial -> inputDriverName , * portInNames ,
  729.                 sizeof ( serial -> inputDriverName ) ) ;
  730.             PtrAndHand ( & serial -> name , * names , 
  731.                 sizeof ( serial -> name ) ) ;
  732.             PtrAndHand ( & serial -> deviceIcon , * iconHandles ,
  733.                 sizeof ( serial -> deviceIcon ) ) ;
  734.         } else {
  735.             break ;
  736.         }
  737.     }
  738.     return err ;
  739. }
  740. *end*
  741.  
  742. This will create four handles with the driver names, device 
  743. names and driver icon handles for all of the available serial 
  744. devices. Then let the user choose with a pop-up menu or 
  745. scrolling list, and save the choice in your settings file. 
  746.  
  747. You can use OpenDriver, SetReset, SetHShake, SetSetBuf, 
  748. SerGetBuf and the other Serial Manager functions on these 
  749. drivers. To write to the serial port, use FSWrite for 
  750. synchronous writes that wait until all is written, or PBWrite 
  751. asynchronously for queuing up data that is supposed to go out 
  752. but you don't want to wait for it. At least once each tim 
  753.  
  754. e through your event loop, you should call SerGetBuf on the in 
  755. driver reference number you got from OpenDriver, and call FSRead 
  756. for that many bytes - neither more nor less. 
  757.  
  758. If you are REALLY interested in doing the right thing, you will 
  759. use the Communications Toolbox Connection Manager instead; this 
  760. will give you access to modems, direct lines, and networks of 
  761. various kinds using the same API! Great for stuff like BBSes 
  762. that may be on a network as well etc. The Comms Toolbox also 
  763. priovides modularized terminal emulat 
  764.  
  765. ion and file transfer tools, although the Apple-suplied VT102 
  766. tool is pretty lame, as is the VT102 mode of the VT320 tool. 
  767.  
  768. *3* TCP/IP and sockets 
  769.  
  770. 3.1) Q: Where is a Berkley sockets library for the Mac? 
  771.  
  772. A: There are some problems with that. MacTCP, the Mac Toolbox 
  773. implementation of TCP/IP, doesn't have an API that looks at all 
  774. like Berkley sockets. For instance, there is ONE paramater-block 
  775. call to do a combined listen()/accept()/bind() - sort of. I have 
  776. heard that there may be a socket library available by ftp from 
  777. MIT but haven't seen it myself. 
  778.  
  779. There is also a pretty good C++ TCP implementation called GUSI 
  780. which is easily handled, and it also is callable from C using 
  781. the Berkley socket API. Apart from TCP, it also handles 
  782. "standard" Mac network protocols such as ADSP. The big 
  783. disadvantage is that it is currently only implemented for MPW. 
  784. The ftp site is nic.switch.ch, software/mac/src/mpw_c. 
  785.  
  786. I can also recommend the Communications Toolbox; for the price 
  787. of using an API that is simpler than the Berkley sockets, you 
  788. get the benefit of being able to use any kind of connection (TCP 
  789. tools are available) 
  790.  
  791. Novell and Wollogong offer commercial socket-like libraries. 
  792.  
  793. 3.2) Q: Where do I find MacTCP? 
  794.  
  795. A: You can buy the MacTCP developers kit from APDA. It is also 
  796. available on E T O, and if you want saner headers than those, 
  797. try ftp to seeding.apple.com. 
  798.  
  799. *4* AppleEvents and the AppleEvent Object Model 
  800.  
  801. 4.1) Q: What are AppleEvents? 
  802.  
  803. A: AppleEvents are a level-5 network protocol. If you are not 
  804. familiar with the ISO network stack, this means it's a way of 
  805. structuring sessions between network entities (programs) that is 
  806. not dependent on the underlying protocol (such as PPC or TCP/IP) 
  807. Despite being a network protocol, they can be very useful on 
  808. Macs that are not on a network. In short, they provide 
  809. applications with a comprehensive way to send arbitrary 
  810. structured data to other applications (or themselves) which 
  811. receive the events through their main event loop. 
  812.  
  813. The AppleEvent Object Model is a way of looking at applications 
  814. and the data they contain, and also a level-6 network protocol. 
  815. You _can_ send AppleEvent Object Model data through AppleEvents 
  816. (and the standard AppleEvents defined in the AppleEvent Registry 
  817. use it) but you don't have to - unless you want to talk with 
  818. other applications, of course, then the AEOM is a lingua franca. 
  819. 4.2) Q: What are the four required AppleEvents? 
  820.  
  821. A: There are four events your application really must implement 
  822. if you want to sell it: the kCoreEventClass class, 
  823. kAEOpenApplication, kAEQuitApplication, kAEOpenDocuments and 
  824. kAEPrintDocuments events IDs. When you support these events (or 
  825. any AppleEvents) you will not get startup info through 
  826. GetAppParams() anymore, unless you run under System 6 of course. 
  827. The kAEOpenApplication event will be sent to you when the user 
  828. double-clicks your app and it's not started yet. When receiving 
  829. it, you can put up a new untitled window. 
  830.  
  831. kAEOpenDocuments is sent when the user double-clicks your apps 
  832. documents. Note that if the first AppleEvent you receive is a 
  833. kAEOpenDocuments event, the user started your app by 
  834. double-clicking its documents. 
  835.  
  836. kAEPrintDocuments is sent when the user selects your documents 
  837. and chooses "Print" in the Finder menu. If this is the first 
  838. AppleEvent you receive, you should print the documents and then 
  839. quit the application again; if you received a kAEOpenApplication 
  840. or kAEOpenDocuments event before this, you should just print the 
  841. documents and close them when you're done. 
  842.  
  843. kAEQuitApplication is sent to you when the user chooses 
  844. "Shutdown" or "Restart" from the Apple Menu. You should ask the 
  845. user whether he wants to save any unsaved changed documents, and 
  846. then quit unless the user presses Cancel. 
  847.  
  848. Interestingly enough, you can use these four AppleEvents to send 
  849. even to non-AE-aware applications, and the system will translate 
  850. these events into fake menu selections for you. 
  851.  
  852. A good way of shutting down the Finder is to send it a Quit 
  853. AppleEvent. You should send a Quit AppleEvent to File Sharing 
  854. Extension before you shut down the Finder, though; the FSE is 
  855. found by looking for a process with the creator 'hhgg'. 
  856.  
  857. 4.3) Q: Are there any limits or tradeoffs with AppleEvents? 
  858.  
  859. A: As always, more power means more responsibility. 
  860.  
  861. AppleEvents sent to applications on other Macs require 
  862. authentification the first time they are sent. If the remote Mac 
  863. allows Guests to link to programs, the INIT AutoGuest 2.0 might 
  864. help (or the code solution that comes with it and you can build 
  865. into your application) 
  866.  
  867. In the first version of the AppleEvent manager, there was a 
  868. total 64K limit on the size of data and overhead. This limit has 
  869. been lifted with the version of the AppleEvent manager that 
  870. comes with AppleScript. 
  871.  
  872. AppleEvents require a lot of memory copying and handle resizing 
  873. in their construction; this means that large AppleEvents may be 
  874. slow in construction, especially when compared to a pure PPC 
  875. Toolbox or ADSP/ASDSP link. 
  876.  
  877. You should use your own application signature as event class for 
  878. AppleEvents you make up, in order not to collide with anybody 
  879. else. Other than that, you are free to make your own events for 
  880. your own needs, though supporting the required events and at 
  881. least a subset of the Core event suite will buy you a lot of 
  882. functinality from within AppleScript. Especially important are 
  883. the Get Current Selection and Set Current Selection events 
  884. (which are really Get/Set Data on the contents of the current 
  885. selection of the application) 
  886.  
  887. The signature for your application SHOULD be registered with DTS 
  888. to avoid conflicts; this is done through e-mail to 
  889. DEVSUPPORT@AppleLink.Apple.Com and the form you use is located 
  890. on the developer CDs and found on ftp.apple.com. 
  891.  
  892. *5* AppleScript 
  893.  
  894. 5.1) Q: How does AppleEvents interface with AppleScript? 
  895.  
  896. A: AppleEvents are the meat and potatoes of AppleScript. If you 
  897. support the AppleEvent Object Model from within your 
  898. application, users can control you through AppleScript. 
  899.  
  900. The first thing you should do is get ahold of Inside Mac: 
  901. Interapplication Communication, and a copy of the AppleEvents 
  902. Registry. The former tells you all you ever need to know about 
  903. AppleEvents, while the latter is paramount for implementing the 
  904. right standard events. If everybody use the standard events, 
  905. dynamic data interchange between any applications will become 
  906. sweet reality! 
  907.  
  908. Then there is the 'aete' resource which lets you put names on 
  909. the events you support, so that users can "Open Terminology" on 
  910. your application from within the Apple Script Editor and use the 
  911. proper AppleScript commands in their scripts. The format of an 
  912. aete resource is defined in Inside Macintosh: Interapplication 
  913. Communication. 
  914.  
  915. 5.2) Q: Can I compile and run scripts from within my 
  916. application? 
  917.  
  918. A: Yes, this is very simple. There are toolbox calls for reading 
  919. scripts, compiling scripts, and executing scripts. (OSACompile, 
  920. OSAExecute) These are all documented in Inside Mac: 
  921. Interapplication Communication. 
  922.  
  923. 5.3) Q: Is this a good way of getting a macro language almost 
  924. for free? 
  925.  
  926. A: "Good" is an understatement. Just let users write scripts, 
  927. load them into menu items and go. Total systems integration in 
  928. under a week, including adding support for the AEOM to your 
  929. application. 
  930.  
  931. There is source code for an application called "MenuScipter" on 
  932. the developer CD which shows you how to do an application with 
  933. all of the menus being AppleScript scripts. 
  934.  
  935. *6* Drawing using QuickDraw 
  936.  
  937. 6.1) Q: Why is CopyBits so slow? 
  938.  
  939. A: It is not. It just requires some hand-holding to get good 
  940. results. The main rules are: Make sure the source and 
  941. destination pixMaps are of the same depth. 
  942.  
  943. Make sure the front color is black and the back color is white. 
  944.  
  945. Use srcCopy and don't use a masking region. 
  946.  
  947. Copy to an unclipped window (the frontmost window). 
  948.  
  949. Make sure the ctSeed values of the source pixMap and dest pixMap 
  950. match. 
  951.  
  952. Copying few and large pixMaps is faster than copying many and 
  953. small ones. Icon-sized sprites count as small ones. 
  954.  
  955. Make sure your source bitmap or pixelMap has the same alignment, 
  956. when adjusted for the source and destination rect expressed in 
  957. global screen coordinates. The necessary alignment is 32 bits (4 
  958. bytes), although 128 bit (16 byte) alignment is probably even 
  959. better on 68040 macs and won't hurt on other macs. 
  960.  
  961. Example of global alignment: 
  962.  
  963. Your window is positioned at (42,100) (H,V) 
  964.  
  965. Your destination rectangle is (10,20)-(74,52) 
  966.  
  967. The alignment coefficient of the rectangle in global coordinates 
  968. is (42+10)*bitDepth where bitDepth is one of 1,2,4,8,16 or 32. 
  969.  
  970. Make sure your source pixmap rect has the same coeffecient 
  971. modulo your alignment factor (in bits) For black&white macs, 
  972. this is still true, although bitDepth is fix at 1. Offscreen 
  973. pixMaps can calculate with a "global posistion" of 0,0 and get 
  974. correct results. 
  975.  
  976. 6.2) Q: Why is CopyBits still too slow? 
  977.  
  978. A: Because there is always some overhead involved in calling 
  979. QuickDraw; you have the trap dispatcher, clipping checks, and 
  980. checking whether the CopyBits call is being recorded in a PICT 
  981. handle (if you called OpenPicture) 
  982.  
  983. If you can't live with this, look at *7* below, but PLEASE try 
  984. and make CopyBits work, and retain the CopyBits code in your 
  985. application, so users with special monitors (accellerator cards, 
  986. PowerBook color screens, Radius Pivot screens) can still play 
  987. your game. (non-game applications don't need more speed than 
  988. CopyBits can give at its max. Promise!) 
  989.  
  990. 6.3) Q: What is the fastest way to set one pixel? 
  991.  
  992. A: NOT SetCPixel()! Assuming you have the correct ForeColor() 
  993. set, you can set the pen size to (1,0) and call Line (0,1) 
  994.  
  995. I have heard PaintRect is good for this but requires slightly 
  996. more code.  Using PaintRect eliminates a trap call. 
  997.  
  998. 6.4) Q: Why do pictures I record suddenly draw as empty space or 
  999. not draw at all? 
  1000.  
  1001. A: When recording pictures, you have to set the clipping area to 
  1002. exactly the frame of the picture you are recording. This is 
  1003. because it is initally set at -32768,32727 in both directions, 
  1004. and offsetting the picture even one pixel when drawing it will 
  1005. result in the region wrapping around and becoming empty. 
  1006.  
  1007. When recording pictures, do this: 
  1008.  
  1009. *code*
  1010. PicHandle h = OpenPicture ( & theRect ) ;
  1011. ClipRect ( & theRect ) ;
  1012.     /* draw the picture */
  1013. ClosePicture ( ) ;
  1014. *end*
  1015.  
  1016. 6.5) Q: Where can I find the format of picture files and 
  1017. resources? 
  1018.  
  1019. A: The format of a picture resource version 1 is defined in a 
  1020. technical note. This format is obsolete. 
  1021.  
  1022. The format of a picture resource version 2 is defined in Old 
  1023. Inside Mac vol V, with addenda in Old Inside Mac vol VI. 
  1024.  
  1025. Some things happen with QuickTime compressed pictures; try the 
  1026. Inside Mac: QuickTime book or wait for Inside Mac: Imaging which 
  1027. is the definite reference on QuickDraw. 
  1028.  
  1029. The format of a picture file is the same as that of a picture 
  1030. resource with 512 added 0 bytes in front. 
  1031.  
  1032. 6.6) Q: GWorlds? 
  1033.  
  1034. A: What about them? They're great. Look them up in Old Inside 
  1035. Mac vol VI. Don't forget to SetGWorld back to what it was before 
  1036. calling WaitNextEvent. 
  1037.  
  1038. 6.7) Q: How do I find the current depth of the screen? 
  1039.  
  1040. A: My question to you is: What screen? Many macs have more than 
  1041. one screen attached. You can use GetDeviceList and walk the 
  1042. devices to find the screen you're looking for (use 
  1043. TestDeviceAttrib to see whether it's a screen) or you can call 
  1044. GetMaxDevice() to find the deepest device your window 
  1045. intersects. 
  1046.  
  1047. Once you have the device handle, finding the depth is just a 
  1048. matter of looking at the dgPMap pixMapHandle, and dereference it 
  1049. to the pmSize field. Done. 
  1050.  
  1051. *7* Drawing directly to screen 
  1052.  
  1053. 7.1) Q: Why is it a bad idea to draw directly to screen? 
  1054.  
  1055. A: Because of several reasons: 
  1056.  
  1057. - You will be incompatible with future display hardware. 
  1058.  
  1059. - You will be incompatible with some present-day display 
  1060. hardware, such as Radius Pivots and PowerBook color screens. 
  1061.  
  1062. - You have to think about a lot of things; testing it all on 
  1063. your own machine is not possible and the chances of crashing are 
  1064. great. 
  1065.  
  1066. - You will be incompatible with future hardware where devices 
  1067. may live in some unaccessible I/O space. 
  1068.  
  1069. 7.2) Q: But I really need to do it. I can't make my animation 
  1070. into a QuickTime movie, and CopyBits is too slow, even when 
  1071. syncing to the screen retrace. 
  1072.  
  1073. A: You have to prepare yourself, and ask these questions: 
  1074.  
  1075. 1) Do I want to support all screens, or just 8-bit devices? 
  1076.  
  1077. 2) Do I have a few weeks of free time to make it work? 
  1078.  
  1079. 3) Do I want to get nasty mail when I break on some hardware and 
  1080. have to rev the application - even if I may not be able to get 
  1081. ahold of the hardware that makes it break? 
  1082.  
  1083. If all you're doing is rendering an image pixel-by-pixel or 
  1084. line-by-line, maybe you can draw directly into an offscreen 
  1085. pixMap/GWorld and then CopyBits the entire GWorld to screen? 
  1086. That will be more compatible, especially if you use the 
  1087. keepLocal flag when creating the GWorld. 
  1088.  
  1089. 7.3) Q: Okay, so how do I get the base address of the screen? 
  1090.  
  1091. A: "The" screen? Which screen? There may be several. The base 
  1092. address may be on an accellerated screen card. There may be more 
  1093. than one screen covering the same desktop area. 
  1094.  
  1095. Due to unfortunate circumstances, there is a bug in 
  1096. GetPixBaseAddr() that causes it to return incorrect results for 
  1097. some versions of System 7. Instead, get the baseAddr directly 
  1098. from the gdPMap handle of the GDHandle for the screen you draw 
  1099. to. This address may need switching to 32bit mode to be valid. 
  1100.  
  1101. 7.4) Q: Quit stalling and give me code! 
  1102.  
  1103. A: Okay, but I'll let you sweat over Inside Mac to figure out 
  1104. what it does. All of it is important; believe me! To make this 
  1105. code run faster, a lot of the things it does can be done once 
  1106. before starting to draw. 
  1107.  
  1108. Make sure that you have a window that covers the area where you 
  1109. are drawing, so other windows will not be overdrawn. Also make 
  1110. sure that you do not do direct-to-screen-drawing while you are 
  1111. in the background. 
  1112.  
  1113. *code*
  1114. /* This is presently untested code */
  1115. /* Value is dependent on what depth the screen has */
  1116. /* This code doesn't work on non-color-quickdraw Macs (i e the MacClassic) */
  1117. /* "where" is in GLOBAL coordinates */
  1118. void
  1119. SetPixel ( Point where , unsigned long value ) {
  1120.  
  1121. Rect r ;
  1122. GDHandle theGD ;
  1123. char * ptr ;
  1124. long rowBytes ;
  1125. short bitsPerPixel ;
  1126. PixMapHandle pmh ;
  1127. Boolean oldMode ;
  1128.  
  1129.     r . left = where . h ;
  1130.     r . top = where    . v ;
  1131.     r . right = r . left + 1 ;
  1132.     r . bottom = r . top + 1 ;
  1133.     theGD = GetMaxDevice ( & r ) ;
  1134.     if ( theGD ) {
  1135.         where . v -= ( * theGD ) -> gdRect . left ;
  1136.         where . h -= ( * theGD ) -> gdRect . top ;
  1137.         pmh = ( * theGD ) -> gdPMap ;
  1138.         rowBytes = ( ( * pmh ) -> rowBytes ) & 0x3fff ;
  1139.         ptr = ( char * ) ( * pmh ) -> baseAddr ;
  1140.         bitsPerPixel = ( * pmh ) -> pixelSize ;
  1141.         oldMode = true32b ;
  1142.         ptr += where . v * rowBytes ;
  1143.         SwapMMUMode ( & oldMode ) ;
  1144.         switch ( bitsPerPixel ) {
  1145.         case 1 :
  1146.             if ( value & 1 ) { 
  1147.                 ptr [ where . h >> 3 ] |= ( 128 >> ( where . h & 7 ) ) ;
  1148.             } else {
  1149.                 ptr [ where . h >> 3 ] &= ~( 128 >> ( where . h & 7 ) ) ;
  1150.             }
  1151.             break ;
  1152.         case 2 :
  1153.             ptr [ where . h >> 2 ] &= ( 192 >> 2 * ( where . h & 3 ) ) ;
  1154.             ptr [ where . h >> 2 ] |= ( value & 3 ) << 2 * ( 3 - ( where . h & 3 ) ) ;
  1155.             break ;
  1156.         case 4 :
  1157.             ptr [ where . h >> 1 ] &= ( where . h & 1 ) ? 0xf : 0xf0 ;
  1158.             ptr [ where . h >> 1 ] |= ( value & 15 ) << 4 * ( 1 - ( where . h & 1 ) ) ;
  1159.             break ;
  1160.         case 8 :
  1161.             ptr [ where . h ] = value ;
  1162.             break ;
  1163.         case 16 :
  1164.             ( ( unsigned short * ) ptr ) [ where . h ] = value ;
  1165.             break ;
  1166.         case 32 :
  1167.             ( ( unsigned long * ) ptr ) [ where . h ] = value ;
  1168.             break ;
  1169.         default :
  1170.             abort ( ) ; /* Should never get here */
  1171.         }
  1172.         SwapMMUMode ( & oldMode ) ;
  1173.     }
  1174. }
  1175. *end*
  1176.  
  1177. *8* Cache issues and other processor differences 
  1178.  
  1179. 8.1) Q: Why does my application work on an SE with accellerator 
  1180. (or a Mac II or Quadra), but not on one without? 
  1181.  
  1182. A: Assuming you're not calling Color QuickDraw (which is not 
  1183. available on accellerated SEs), you most probably have an 
  1184. odd-aligned word access somewhere. 
  1185.  
  1186. The 68000 does not allow words or longwords to be read from odd 
  1187. addresses, while the 68020 and up relaxes this restriction (it 
  1188. still is slower than aligned-word access though) 
  1189.  
  1190. This may or may not crash depending on your compiler: 
  1191.  
  1192. *code*
  1193. struct foo {
  1194.     char c1 ;
  1195.     char c2 ;
  1196.     char c3 ;
  1197.     char c4 ;
  1198.     char c5 ;
  1199. } bar ;
  1200.  
  1201.     long * x = ( long * ) & bar . c2 ;
  1202.     * x = 0x12345678 ; /* X is odd if compiler doesn't pad */
  1203.  
  1204. This WILL crash on an SE/Plus/Classic/PB100:
  1205.  
  1206. char foo [ 10 ] ;
  1207.  
  1208.     long * x = ( long * ) & foo [ 1 ] ;
  1209.     * x = 0x12345678 ;
  1210.  
  1211. *end*
  1212.  
  1213. 8.2) Q: Why does my application work on a IIci but not on a 
  1214. Quadra? 
  1215.  
  1216. A: Two reasons: 
  1217.  
  1218. 1) The Quadras 900 and 950 have special processors that handle 
  1219. the serial ports; if you write directly to the serial chips, you 
  1220. will crash (this goes for the IIfx as well) 
  1221.  
  1222. 2) The Quadras have 68040 processors, as have the Centrises. 
  1223. These processors have separate instruction and data caches (like 
  1224. the 68030) but they are larger (4K each) and unlike the 68030 
  1225. which is write-through data cached, the 68040 is copy-back data 
  1226. cached. This means that changes you make to "your code" aren't 
  1227. really changed all the time, since the changes may still be in 
  1228. the data cache and not written to memory when the CPU reads that 
  1229. part of memory into its I-cache. Even worse; that part might 
  1230. already have been read into the I-cache before you change it in 
  1231. the D-cache, meaning that writing out the D-cache will still not 
  1232. be enough. You need to flush both the caches when writing 
  1233. self-modifying code. 
  1234.  
  1235. Self-modifying code includes code that builds its own jump 
  1236. tables and code that decrypts itself and code that "stubs" MDEFs 
  1237. or WDEFs to jump back into the application code. 
  1238.  
  1239. You flush the cache using FlushDataCache() which is implemented 
  1240. if Gestalt says you have a 68020 or better processor (or if the 
  1241. _HwDispatch trap is implemented) 
  1242.  
  1243. 8.3) Q: Why does my application work on my Quadra but not on my 
  1244. accellerated SE? 
  1245.  
  1246. A: You're probably calling Color QuickDraw without first 
  1247. checking if it's available. The following machines do not have 
  1248. color QuickDraw in ROM nor RAM: 
  1249.  
  1250. Mac Plus, Mac SE, Mac Classic, Mac Luggable, PowerBook 100, 
  1251. Outbound 
  1252.  
  1253. 8.4) Q: I do check for color quickdraw, but crash nevertheless. 
  1254.  
  1255. A: _Gestalt lies under some versions of System 7; it says that 
  1256. non-color machines HAVE color QuickDraw when you test using the 
  1257. gestaltQuickdrawFeatures selector. 
  1258.  
  1259. Instead, check the gestaltQuickdrawVersion selector, if it 
  1260. returns >= gestalt8BitQuickdraw then you can safely use 
  1261. gestaltQuickdrawFeatures, else you only have b/w QuickDraw. 
  1262.  
  1263. 8.5) Q: Why are there no C/C++ compilers that optimize for the 
  1264. Mc68040? 
  1265.  
  1266. A: Beats me; optimizing for the 68040 can make programs up to 
  1267. 50% faster on that chip while still losing nothing, or very 
  1268. little (less than 10%) on older chips. 
  1269.  
  1270. *9* Inflammatory subjects 
  1271.  
  1272. 9.1) Q: What about pre-emptive multitasking? 
  1273.  
  1274. A: To the user, the Mac multitasking method, which builds upon 
  1275. each application calling WaitNextEvent, GetNextEvent or 
  1276. EventAvail every so often and the Process Manager/MultiFinder 
  1277. switching applications only at such calls, is at least as good 
  1278. as preemtive multitasking, because the present system 
  1279. priotitizes user interface responsiveness over everything else. 
  1280. The only shortfall about this is formatting floppies, which 
  1281. locks up the Mac CPU. This is because the Mac floppy controller 
  1282. is really stupid, and would happen even if the Mac multitasked 
  1283. preemptively. 
  1284.  
  1285. There IS "real" pre-emptive multitasking available for use in 
  1286. Mac applications; the expensive way is buying A/UX 3.0 which can 
  1287. have Mac applications written as UNIX processes; the cheap way 
  1288. is installing the Thread Manager which will allow you to create 
  1289. pre-emptive threads. However, the restrictions on those threads 
  1290. are the same as those on Time Manager tasks: don't call any 
  1291. function in an unloaded segment, and don't call QuickDraw or any 
  1292. toolbox call which may move memory (which are most ToolBox 
  1293. calls; paradoxally, BlockMove is safe :-) as are, surprisingly, 
  1294. FSRead and FSWrite) 
  1295.  
  1296. There are several problems with making the Mac OS preemptive; 
  1297. including apps that draw outside their windows or directly to 
  1298. screen, user dragging and other issues. 
  1299.  
  1300. 9.2) Q: What about protected memory? I'm sick and tired of 
  1301. re-booting when my application crashes. 
  1302.  
  1303. A: Write better software! 
  1304.  
  1305. Or install The Debugger from Jasik Designs, which can provide 
  1306. your application with write-protection of critical parts of 
  1307. memory. This may only work for 030 Macs, though. 
  1308.  
  1309. Making the Mac OS memory-protected is tricky, because 
  1310. applications expect to be able to write to low memory, the 
  1311. system heap, temporary memory, window lists, and even each 
  1312. other's heaps in some interapplication communication solutions 
  1313. that date back to before AppleEvents and the PPC Toolbox. 
  1314.  
  1315. *10* Handles; they are driving me crazy 
  1316.  
  1317. 10.1) Q: What is a handle? 
  1318.  
  1319. A: A handle is a pointer to a pointer to something. However, it 
  1320. is more than that; creating a handle by taking the address of 
  1321. one of your own pointers does NOT create a Handle; the Memory 
  1322. Manager will only deal properly with Handles that are created 
  1323. using NewHandle or something that calls it (such as NewRgn or 
  1324. GetResource) 
  1325.  
  1326. 10.2) Q: When do I have to lock a Handle? 
  1327.  
  1328. A: The contents of a Handle may move, and when it does, the 
  1329. pointer your handle is pointing to is changed to point to the 
  1330. new address so your handle is always valid. The toolbox may call 
  1331. the memory manager to allocate more memory pretty much anytime 
  1332.  
  1333. you call it (the toolbox) and when memory is allocated, your 
  1334. handle may move in memory. Don't dereference a handle into a 
  1335. pointer (or take the address of a field in a record a handle is 
  1336. double-pointing to) and then call the toolbox and expect the 
  1337. pointer to still be valid. The only way to ensure that the 
  1338. pointer will still be valid is to call HLock on the handle to 
  1339. lock it. 
  1340.  
  1341. Use HGetState and HSetState to save & restore the "locked" state 
  1342. of a handle when you lock it. 
  1343.  
  1344. 10.3) Q: How do I dispose of Handles? 
  1345.  
  1346. A: DisposeHandle (formerly called DisposHandle) once and ONLY 
  1347. once will do the trick. Trying to dispose of an already disposed 
  1348. Handle is an error. DoubleTrouble (see above) will catch such 
  1349. bugs when they do occur. 
  1350.  
  1351. 10.4) Q: What about resources? 
  1352.  
  1353. A: Calling GetResource returns NULL if the resource is not found 
  1354. or there is not enough memory, else it returns a handle to the 
  1355. resource. This handle may be moved or locked like any other 
  1356. handle, but DO NOT call DisposeHandle to get rid of a resource 
  1357. handle - call ReleaseResource. DisposeResource (see above) will 
  1358. catch this kind of bug. 
  1359.  
  1360. Remember that AddResource makes a resource handle out of an 
  1361. ordinary handle, and RmveResource or DetachResource makes an 
  1362. ordinary handle out of a resource handle. You cannot call 
  1363. AddResource with a resource handle; you have to DetachResource 
  1364. it first. 
  1365.  
  1366. Resource handles are automagically disposed when the resource 
  1367. file they belong to is closed. 
  1368.  
  1369. 10.5) Q: I'm trying to use a largish array in Think C, but get a 
  1370. "code overflow" error. This is valid C, why doesn't it work? 
  1371.  
  1372. A: The ANSI standard does not guarantee that any structure 
  1373. larger than 32767 bytes be correctly handled. Because of 
  1374. historical constraints, the Mac memory model is built around 
  1375. several small blocks of size 32K or less; these are used both 
  1376. for code and global/static data. If you want to use more code or 
  1377. data, you have to turn on "far code" or "far data" - you still 
  1378. will not get around the restriction of 32K code or data per 
  1379. compiled file, though. 
  1380.  
  1381. As opposed to, say, DOS or Windows, however, you can allocate as 
  1382. much memory as you want (and there is in the machine) and step 
  1383. through it using ordinary pointers; it's just that global and 
  1384. static data space is addressed off the A5 register using a 16bit 
  1385. displacement addressing mode in the 68000 processor. 
  1386.  
  1387. *11* _Gestalt and compatibility 
  1388.  
  1389. 11.1) Q: I see all these people call Gestalt without first 
  1390. checking whether it's implemented. Isn't that bad? 
  1391.  
  1392. A: No; Gestalt and a few other traps (the HXxx file manager 
  1393. traps, and FindFolder) are implemented using glue so they do the 
  1394. right thing even if the trap is not implemented. 
  1395.  
  1396. If you want to get rid of the glue, you can #define 
  1397. SystemSevenOrLater (and, using Think C/C++, re-pre-compile 
  1398. MacHeaders) However, then you will be responsible for checking 
  1399. for these features before you use them. 
  1400.  
  1401. 11.2) Q: What more functions are implemented in glue? 
  1402.  
  1403. A: Wake Up and Smell the Glue! [by Matthias Neeracher] 
  1404.  
  1405. How often have you wished you could use that cool new ToolBox 
  1406. call, but didn't want to make your application System 7 
  1407. dependent? Well, it might be that you *could* in fact have used 
  1408. the call. Several traps are implemented in glue, that is, much 
  1409. of their functionality is linked into your application and thus 
  1410. available even if you are running under an old System. 
  1411.  
  1412. This list applies to MPW 3.2 and should also be valid for the 
  1413. current version of Think C. If you find any inaccuracies, please 
  1414. report them to me. (neeri@iis.ee.ethz.ch) 
  1415.  
  1416. FSOpen: Tries first OpenDF, then Open. 
  1417.  
  1418. HOpenResFile: Full functionality emulated if trap not available 
  1419.  
  1420. HCreateResFile: Full functionality emulated if trap not 
  1421. available 
  1422.  
  1423. FindFolder: Under System 6, understands the following values for 
  1424. folderType and returns the System Folder for all of them: 
  1425.  
  1426. kAppleMenuFolderType 
  1427.  
  1428. kControlPanelFolderType 
  1429.  
  1430. kExtensionFolderType 
  1431.  
  1432. kPreferencesFolderType 
  1433.  
  1434. kPrintMonitorDocsFolderType 
  1435.  
  1436. kStartupFolderType 
  1437.  
  1438. kSystemFolderType 
  1439.  
  1440. kTemporaryFolderType 
  1441.  
  1442. SysEnvirons: Full functionality emulated if trap not available 
  1443.  
  1444. NewGestalt: Returns an error if not implemented 
  1445.  
  1446. ReplaceGestalt: Returns an error if not implemented 
  1447.  
  1448. Gestalt: The following selectors are always implemented: 
  1449.  
  1450. vers    mach    sysv    proc    fpu     
  1451.  
  1452. qd      kbd     atlk    ram     lram    
  1453.  
  1454. 11.3) Q: I have to support System 6, don't I? 
  1455.  
  1456. A: It would be foolish to lock yourself out of the many benefits 
  1457. the System 7 API provides for software that you start to write 
  1458. now. Some of the System 6 and older things (likely SFGetFile and 
  1459. wdRefNums among others) will be phased out of the interfaces and 
  1460. lose support; especially on future platforms. 
  1461.  
  1462. The installed base of System 7 is larger than that of System 6; 
  1463. this is not surprising because Apple has been shipping System 7 
  1464. for several years with all new machines, including the LCII, 
  1465. Classic II, Performas and Color Classic. Another argument is 
  1466. that newer computer owners (having System 7) are much more 
  1467. likely to buy new software than old computer owners who have 
  1468. systems that already do what they want them to. 
  1469.  
  1470. The added work to support both System 6 and System 7 is 
  1471. significant; if you have the time and money you may want to do 
  1472. it, but only supporting System 6 and not System 7 is doomed to 
  1473. fail in the market of today. 
  1474.  
  1475. Some may call this position subjective; I call it business sense 
  1476. based on market demographics. A rule of thumb may be that if you 
  1477. target color machines only, you can just as well demand System 7 
  1478. as well. 
  1479.  
  1480. *12* Standalone code and dynamic linking 
  1481.  
  1482. 12.1) Q: I've got a CODE resource off in limboland (sometimes 
  1483. called the resource fork) and I want to open it... what do I do? 
  1484. A: You open the file you have the code resource in, load the 
  1485. resource and lock it high (don't unlock it first, since someone 
  1486. else may be using it). Then you cast the handle to a function 
  1487. pointer, and call it normally. 
  1488.  
  1489. Suppose your code resource is compiled as a SACD id 128, and is 
  1490. defined as: 
  1491.  
  1492. *code*
  1493. long
  1494. main ( MyParams * params ) {
  1495.     switch ( params -> message ) {
  1496.     case messageInit :
  1497.         return init ( params ) ;
  1498.     ...
  1499.     }
  1500.     return 0L ;
  1501. }
  1502. *end*
  1503.  
  1504. Also suppose you already have the vRefNum, parID and name of the 
  1505. resource file you want to use. Do this: 
  1506.  
  1507. *code*
  1508.     setup_paramblock ( & the_params ) ;
  1509.     the_params . message = messageInit ;
  1510.     refNum = HOpenResFile ( vRefNum , parID , name , fsRdPerm ) ;
  1511.     if ( refNum < 1 ) {
  1512.         fail ( ResError ( ) ) ;
  1513.     }
  1514.     the_code = GetResource ( 'SACD' , 128 ) ;
  1515.     HLockHi ( the_code ) ;
  1516.     retval = ( * ( ( long ( * ) ( MyParams * ) ) StripAddress ( * the_code ) ) ) ( & the_params ) ;
  1517.     ...
  1518. *end*
  1519.  
  1520. The StripAddress is important; if your app is running in 24bit 
  1521. mode, the resource handle may contain tag bits and you don't 
  1522. want strange things to happen if the code resource switches into 
  1523. 32bit mode (which QuickDraw may do, incidentally)
  1524.  
  1525. Exactly how you structure your calling conventions is up to you; 
  1526. there is no accepted standard (except for HyperCard XCMDs, but 
  1527. that is probably overkill for you). 
  1528.  
  1529. *13* 
  1530.  
  1531. 13.1) Q: How do I read the modifier keys of the keyboard? 
  1532.  
  1533. A: Just call EventAvail and check the event.modifiers field. 
  1534. Only works when you are in the foreground. You can also use 
  1535. GetKeys(), or (as a last resort) check the lo-mem global KeyMap 
  1536. directly. 
  1537.  
  1538. 13.2) Q: How do I move the mouse cursor to a specific position?
  1539.  
  1540. A: Wait! Don't do it! There has to be a better way!
  1541.  
  1542. If you feel you HAVE to do it (for a game or VERY special
  1543. simulation situation) you can use the Cursor Device Manager
  1544. documented in the tech notes on ftp.apple.com. If that
  1545. manager is not installed, as it's not on older Macs, you can
  1546. use the following code:
  1547.  
  1548. ----- How to move the mouse (info in C): -----
  1549. you need to have some low-memory globals defined. they may be defined in
  1550. SysEqu.h.
  1551.  
  1552. #define MTemp 0x828
  1553. #define RawMouse 0x82c
  1554. #define CrsrNewCouple 0x8ce
  1555.  
  1556. note that CrsrNewCouple is actually a combination of two globals, just
  1557. to make our life slightly easier.
  1558.  
  1559. the code i use to move the mouse is:
  1560.  
  1561. *code*
  1562. void
  1563. MoveMouseTo ( Point where ) {
  1564.  
  1565.     HideCursor ( ) ;
  1566.     * ( Point * ) RawMouse = where ;
  1567.     * ( Point * ) MTemp = where ;
  1568.     * ( short * ) CrsrNewCouple = -1 ;
  1569.     ShowCursor ( ) ;
  1570. }
  1571. *end*
  1572.  
  1573. you need to hit a couple more global variables if you want this to
  1574. work properly in a multiple-monitor system, but i forget what they are 
  1575. offhand. poke through SysEqu.h, and you should be able to figure it out
  1576. without a problem.
  1577. ----------------------------------------------
  1578.  
  1579. On the PowerPC, these lo-mem globals may not be available for
  1580. native applications; however, all Power Macintoshes implement the
  1581. Cursor Device Manager.
  1582.  
  1583. There is also a file on nada.kth.se:pub/hacks/mac-faq/MoveMouse.c
  1584. which shows how to use the Cursor Device Manager, written by an
  1585. excellent Apple engineer. Grab!
  1586.  
  1587.  
  1588. *14* QuickTime 
  1589.  
  1590. 14.1) Q: I want to write a Amiga QuickTime player and need the 
  1591. CODEC format details. 
  1592.  
  1593. A: Although the structure of QuickTime movies is well documented 
  1594. in Inside Mac: QuickTime, the inner workings of the Apple 
  1595. compression modules is a trade secret that Apple will only 
  1596. license to you at great cost. Perhaps it's time for a freeware, 
  1597. cross-platform QuickTime codec? 
  1598.  
  1599. *15* Windows, Menus and Dialogs
  1600.  
  1601. 15.1) Q: My menus don't show up in the menu bar
  1602.  
  1603. A: If your menus are hiearchical, you'll have to install them
  1604. manually; GetNewMBar won't do it for you. See also 15.2.
  1605.  
  1606. 15.2) Q: When the user selects my menus, I get strange results
  1607. back; they seem to have different menu IDs than my menus?
  1608.  
  1609. A: The Menu ID as used by the menu manager is NOT the same
  1610. thing as the MENU resource ID (used in the MBAR resource and
  1611. with GetMenu()) When you create a MENU, ResEdit sets the menu
  1612. ID to the MENU resource ID, but if you re-number the resource,
  1613. you will have to open the menu in ResEdit and change the menu
  1614. ID usiung the "Edit MENU ID" menu item.
  1615.  
  1616. 15.3) Q: I use GetMenu() to find a menu in the menu bar, and then
  1617. change it, but it seems I have a memory leak OR my changes
  1618. don't "punch through"
  1619.  
  1620. A: GetMenu() is only intended if you don't already have the
  1621. menu "in memory." The call you should use almost all the time
  1622. is GetMHandle() which gets the handle to a menu in the current
  1623. menu bar by its menu ID (not resource id)
  1624.  
  1625. *16* Ice Cream and Frozen Yoghurt 
  1626.  
  1627. 16.1) Q: Dessert? 
  1628.  
  1629. A: Honey Hill Farms Cookie Jar Frozen Yoghurt or Haagen-Dazs 
  1630. Raspberry & Cream Ice Cream.
  1631.  
  1632. Hokey-Pokey icecream with chocolate sauce and (for those who 
  1633. like their brain food firmer) Almond and Double Chocolate 
  1634. CookieTime cookies!? [Denis Birnie]
  1635. -- 
  1636.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  1637.    This signature is kept shorter than 4 lines in the interests of UseNet
  1638.    S/N ratio.
  1639.